package com.taotao.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.taotao.comm.pojo.EasyUITreeNode;
import com.taotao.dao.TbItemCatMapper;
import com.taotao.pojo.TbItemCat;
import com.taotao.pojo.TbItemCatExample;
import com.taotao.pojo.TbItemCatExample.Criteria;
import com.taotao.service.ItemCatService;

@Service
public class ItemCatServiceImpl implements ItemCatService{
	@Autowired
	private TbItemCatMapper itemCatMapper;


	@Override
	public List<EasyUITreeNode> getEasyUITreeNode(long parentId) {
		//设置查询条件
		TbItemCatExample example = new TbItemCatExample();
		Criteria criteria = example.createCriteria();
		criteria.andParentIdEqualTo(parentId);
		List<TbItemCat> list = itemCatMapper.selectByExample(example);
		
		//转换成EasyUITreeNode列表
		List<EasyUITreeNode> result = new ArrayList<>();
		for (TbItemCat itemCat : list) {
			EasyUITreeNode treeNode = new EasyUITreeNode();
			treeNode.setId(itemCat.getId());
			
			treeNode.setState(itemCat.getIsParent()?"closed":"open");
			
			treeNode.setText(itemCat.getName());
			
			result.add(treeNode);
		}
		
		return result;
	}
}
